package com.lecture.java8.date;

import java.util.*;
import java.util.stream.Collectors;

/**
 * @author luyn
 * @version 1.0
 * @description
 * @date 2020/9/7 19:05
 */
public class DateTest {

    public static void maind(String[] args) {
        Date date1 = new Date(1689214417000L);
        Date date2 = new Date(1689217642000L);


        // 计算时间差，以毫秒为单位
        long timeDiff = date2.getTime() - date1.getTime();

        // 将时间差转换为时、分、秒
        long seconds = timeDiff / 1000;
        long minutes = seconds / 60;
        long hours = minutes / 60;
        long days = hours / 24;

        // 计算剩余的秒数、分钟数和小时数
        long remainingSeconds = seconds % 60;
        long remainingMinutes = minutes % 60;
        int remainingHours = (int) (hours % 24);

        // 创建一个Time对象，表示时间差
        //Time timeDiffObj = new Time(remainingHours, (int)remainingMinutes, (int) remainingSeconds);

        String interval = "";
        if (days != 0) {
            interval += days + "天，";
        }
        if (remainingHours != 0) {
            interval += remainingHours + "小时，";
        }

        if (remainingMinutes != 0) {
            interval += remainingMinutes + "分钟，";
        }

        if (remainingSeconds != 0) {
            interval += remainingSeconds + "秒。";
        }
        // 输出时间差
        System.out.println("Time difference: " + days + " days, " + remainingHours + " hours, " + remainingMinutes + " minutes, " + remainingSeconds + " seconds");
        System.out.println(interval);
    }

    public static long getMinuteTimestamp(long timestamp) {
        return timestamp - timestamp % 60000;
    }

    public static void main(String[] args) {
        int x = 65535;
        int y = x * x;
        System.out.println(y);
        List<String> list = Arrays.asList("一值", "二值", "五值", "三值", "一值", "四值");


        // 指定排序顺序
        List<String> sortOrder = Arrays.asList("一值", "二值", "三值", "四值", "五值");

        // 分组并按照指定的排序顺序排序
        Map<String, List<String>> result = list.stream()
                .collect(Collectors.groupingBy(s -> s, LinkedHashMap::new, Collectors.toList()))
                .entrySet().stream()
                .sorted(Comparator.comparing((Map.Entry<String, List<String>> entry ) -> sortOrder.indexOf(entry.getKey())))
                .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (u, v) -> u, LinkedHashMap::new));

        // 输出结果
        Set<Map.Entry<String, List<String>>> entries = result.entrySet();
        System.out.println(result);
        int[] a = {0,1};
        int sum = sum(a, 0);
        System.out.println(sum);
    }

    public static int sum(int[] a,int len) {
        int i,sum = 0;
        for (i = 0; i <= len - 1; i++) {
            sum += a[i];
        }
        return sum;
    }
}
